package org.bedracket.pgeg.capability;

import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.util.INBTSerializable;
import org.bedracket.pgeg.util.Helpers;

public class ManaLevelCapability implements INBTSerializable<CompoundTag> {

    private int maxManaLevel = 20;
    private float manaLevel = 0;

    public float getManaLevel() {
        return manaLevel;
    }

    public int getMaxManaLevel() {
        return maxManaLevel;
    }

    public void setManaLevel(float level) {
        this.manaLevel = level;
    }

    public void setMaxManaLevel(int level) {
        this.maxManaLevel = level;
    }

    public void regenManaLevel(float level) {
        this.setManaLevel(this.getManaLevel() + level);
    }

    public void reduceManaLevel(float level) {
        this.setManaLevel(this.getManaLevel() - level);
    }

    @Override
    public CompoundTag serializeNBT() {
        CompoundTag compound = new CompoundTag();
        compound.putFloat(Helpers.namespace("PlayerManaLevel"), this.getManaLevel());
        compound.putInt(Helpers.namespace("PlayerMaxManaLevel"), this.getMaxManaLevel());
        return compound;
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        this.setManaLevel(nbt.getFloat(Helpers.namespace("PlayerManaLevel")));
        this.setMaxManaLevel(nbt.getInt(Helpers.namespace("PlayerMaxManaLevel")));
    }
}
